class code2 {
    //dp问题
    public int minFlipsMonoIncr(String s) {
        int n = s.length();
        //当前下标为0和1的最小翻转次数
        int[] dp0 = new int[n];
        int[] dp1 = new int[n];

        //初始化
        char c = s.charAt(0);
        if(c=='0') {
            dp1[0] = 1;
        } else {
            dp0[0] = 1;
        }

        //求出dp
        for(int i=1;i<n;i++) {
            char ch = s.charAt(i);
            if(ch=='0') {
                dp0[i] = dp0[i-1];
                dp1[i] = Math.min(dp0[i-1],dp1[i-1])+1;
            } else {
                dp0[i] = dp0[i-1]+1;
                dp1[i] = Math.min(dp1[i-1],dp0[i-1]);
            }
        }

        return Math.min(dp0[n-1],dp1[n-1]);
    }
}